﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Copad.BusinessCard.DAL;
using Copad.BusinessCard.Model;
using System.Linq.Expressions;

namespace Copad.BusinessCard.BLL
{
    public class BLL<T> where T : StandardModel
    {
        protected DataBase dataBase = new DataBase();
        protected Entities entities = new Entities();

        public virtual void Insert(T model)
        {
            dataBase.BeginTransaction();
            dataBase.Insert(model);
            dataBase.EndTransaction();
        }

        public virtual void Delete(T model)
        {
            dataBase.Delete(model);
        }

        public virtual void Delete(long id)
        {
            dataBase.Delete<T>(x => x.ID == id);
        }

        public virtual List<T> Get(Expression<Func<T, bool>> predicate = null)
        {
            return dataBase.Select<T>(predicate);
        }

        public virtual void Update(T model)
        {
            dataBase.Update(model);
        }
    }
}
